package com.translate.web.service.impl;

import com.translate.web.dao.WithdrawalMapper;
import com.translate.web.param.contract.IUserIdParam;
import com.translate.web.param.contract.IWithdrawalAddParam;
import com.translate.entity.Withdrawal;
import com.translate.web.service.IWithdrawalService;
import com.basic.service.impl.BaseServiceImpl;
import com.common.util.CopyEntity;
import com.param.contract.IPage;

import org.springframework.stereotype.Service;

@Service
public class WithdrawalServiceImpl extends BaseServiceImpl<Withdrawal> implements IWithdrawalService {
	public WithdrawalServiceImpl(WithdrawalMapper mapper) {
		super(mapper);
	}

	protected void insertPropteris(Withdrawal data) {
		long time = System.currentTimeMillis() / 1000;
		data.setCreateTime(time);
		data.setUpdateTime(time);
		
		data.setAmountStatus((byte) 0);
		
		data.setStatus((byte) 0);
		
		data.setApplyTime(time);
		
	}

	protected void updatePropteris(Withdrawal data) {
		data.setUpdateTime(System.currentTimeMillis() / 1000);
	}

	protected Class<Withdrawal> getEntityClass() {
		return Withdrawal.class;
	}
	
	
	
	@Override
	public <P> int parseInsert(P param, Class<Withdrawal> target) {
		
		Withdrawal copyEntity = CopyEntity.copyEntity(param, target);
		
		insertPropteris(copyEntity);
		
		copyEntity.setUserId((int) ((IWithdrawalAddParam) param).getUserId());
		
		return this.insert(copyEntity);
		
	}

	@Override
	protected <S extends IPage> String sqlByGetCounttAfterProcesser(S param) {
		
		IUserIdParam sqlParam = (IUserIdParam) param;
		
		Integer id = sqlParam.getUserId();
		
		return super.sqlByGetCount(" user_id = " + id);
	}

	@Override
	protected <S extends IPage> String sqlByGetPageListAfterProcesser(S param) {
		IUserIdParam sqlParam = (IUserIdParam) param;
		
		Integer id = sqlParam.getUserId();
		
		return super.sqlByGetPageList(" and  user_id = " + id);
	}
	
	protected boolean continueColumns(String columns) {
		return columns.equals("updateTime") || columns.equals("userId") || columns.equals("");
	}
}